﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SWS.PIP.DM;
using TMPipeTopology;
using System.ComponentModel;

namespace SWS.PIP.CMD
{
	/// <summary>
	/// 数据行状态
	/// 字段		颜色		备注
	/// UNCHANGE	Issue颜色	最终状态
	/// NEW			白			该行为新建行，可更新，更新后状态为UPDATE
	/// UPDATE					中间状态，指示需要刷新改行数据，刷新完成后变更状态为UNCHANGE
	/// DELETE		蓝			待移除行，可删除，删除后状态变更为DELETED
	/// DELETED					中间状态，指示需要删除改行
	/// CHANGE		青			需要更新信息，刷新后状态变更为UPDATE
	/// ERROR		红			模型数据计算出错，可更新，更新后状态|UPDATE，刷新后状态状态&ERROR
	/// NULL		浅蓝		留白页
	/// </summary>
	public enum RowStatus
	{
		UNCHANGE		= 0,		//未变化
		CHANGEATTR		= 1 << 0,	//属性变化
		CHANGENODEFROM	= 1 << 1,
		CHANGENODETO	= 1 << 2,
		DELETE			= 1 << 3,   //删除
		DELETED			= 1 << 4,	//已删除（中间状态）
		NEW				= 1 << 5,   //新建
		UPDATE			= 1 << 6,   //更新（中间状态）
		ERROR			= 1 << 7,   //数据错误
		NULL			= 1 << 8,   //留白页
		CHANGEOID		= 1 << 9,	//修改spooloid

		DBStatus		= 1 << 10	//仅数据库数据
	}

	class SpoolInfoTable
	{
		#region 
		public static string CalculateCode			= "CalculateCode";
		public static string Spool_oid				= "oid";
		public static string Block_oid				= "Block_oid";
		public static string SpoolFullName			= "SpoolFullName";
		public static string Status					= "Status";
		public static string SpoolFromModel			= "SpoolFromModel";//绑定spool对象

		public static string DrawNo					= "DrawNo";
		public static string DrawNoDisplay			= "图号";
		public static string PageNo					= "PageNo";
		public static string PageNoDisplay			= "页码";
		public static string Zone					= "Zone";
		public static string ZoneDisplay			= "区域";
		public static string Block					= "Block";
		public static string BlockDisplay			= "分段";
		public static string Name					= "Name";
		public static string NameDisplay			= "小票号";
		public static string Weight					= "Weight";
		public static string WeightDisplay			= "重量";
		public static string Type					= "Type";
		public static string TypeDisplay			= "管种";
		public static string GroupType				= "GroupType";
		public static string GroupTypeDisplay		= "管族代码";
		public static string SpecName				= "SpecName";
		public static string SpecNameDisplay		= "材料等级";
		public static string TestPressure			= "TestPressure";
		public static string TestPressureDisplay	= "实验压力";
		public static string InnerTreatment			= "InnerTreatment";
		public static string InnerTreatmentDisplay	= "内表面处理";
		public static string OutterTreatment		= "OutterTreatment";
		public static string OutterTreatmentDisplay = "外表面处理";
		public static string Response				= "Response";
		public static string ResponseDisplay		= "责任人";
		public static string SpoolStatusDisplay		= "状态";
		public static string UpdateTimeDisplay		= "更新时间";
		public static string StartInfo				= "StartInfo";
		public static string StartInfoDisplay		= "起点";
		public static string EndInfo				= "EndInfo";
		public static string EndInfoDisplay			= "终点";
		//public static string PlusSpoolDescription = "PlusSpoolDescription";
		//public static string PlusSpoolDescriptionDisplay = "小票描述";
		//public static string PlusSpoolMaterialGrade = "PlusSpoolMaterialGrade";
		//public static string PlusSpoolMaterialGradeDisplay = "材料级别";
		//public static string PlusSpoolClass = "PlusSpoolClass";
		//public static string PlusSpoolClassDisplay = "等级";
		//public static string PlusIsSRTP = "PlusIsSRTP";
		//public static string PlusIsSRTPDisplay = "是否属于返港";
		//public static string PlusProductionLine = "PlusProductionLine";
		//public static string PlusProductionLineDisplay = "管线";
		//public static string PlusInnerSurfaceArea = "PlusInnerSurfaceArea";
		//public static string PlusInnerSurfaceAreaDisplay = "内表面积";
		//public static string PlusOuterSurfaceArea = "PlusOuterSurfaceArea";
		//public static string PlusOuterSurfaceAreaDisplay = "外表面积";
		//public static string PlusSpoolLength = "PlusSpoolLength";
		//public static string PlusSpoolLengthDisplay = "小票长度";
		//public static string PlusSpoolNPD = "PlusSpoolNPD";
		//public static string PlusSpoolNPDDisplay = "通径";
		//public static string PlusSpoolPOD = "PlusSpoolPOD";
		//public static string PlusSpoolPODDisplay = "外径";
		//public static string PlusSpoolWallThickness = "PlusSpoolWallThickness";
		//public static string PlusSpoolWallThicknessDisplay = "壁厚";
		//public static string PlusWBS = "PlusWBS";
		//public static string PlusWBSDisplay = "WBS";
		#endregion

		/// <summary>
		/// 构建一个包含指定列的table表
		/// </summary>
		/// <returns></returns>
		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("SpoolInfo");
			dt.Columns.Add(CalculateCode, typeof(string));
			dt.Columns.Add(SpoolFullName, typeof(string));
			dt.Columns.Add(Spool_oid, typeof(string));
			dt.Columns.Add(Status, typeof(int));
			dt.Columns.Add(SpoolStatusDisplay, typeof(string));
			dt.Columns.Add(NameDisplay, typeof(string));
			dt.Columns.Add(DrawNoDisplay, typeof(string));
			dt.Columns.Add(PageNoDisplay, typeof(string));
			dt.Columns.Add(Block_oid, typeof(string));
			dt.Columns.Add(WeightDisplay, typeof(double));
			dt.Columns.Add(TypeDisplay, typeof(string));
			dt.Columns.Add(GroupTypeDisplay, typeof(string));
			dt.Columns.Add(SpecNameDisplay, typeof(string));
			dt.Columns.Add(TestPressureDisplay, typeof(string));
			dt.Columns.Add(InnerTreatmentDisplay, typeof(string));
			dt.Columns.Add(OutterTreatmentDisplay, typeof(string));
			dt.Columns.Add(StartInfoDisplay, typeof(string));
			dt.Columns.Add(EndInfoDisplay, typeof(string));
			dt.Columns.Add(UpdateTimeDisplay, typeof(string));
			dt.Columns.Add(ResponseDisplay, typeof(string));

			dt.Columns.Add(SpoolFromModel, typeof(object));

			return dt;
		}

		/// <summary>
		/// 将小票信息构建成tableRow
		/// </summary>
		/// <param name="oSMgntSpoolInfo"></param>
		/// <param name="dr"></param>
		internal static void AddRow(DataTable oDT, SMgnt_SpoolInfo oSMgntSpoolInfo)
		{
			DataRow dr = oDT.NewRow();

			SetRowContent(dr, oSMgntSpoolInfo);

			oDT.Rows.Add(dr);
		}

		internal static void SetRowContent(DataRow row, SMgnt_SpoolInfo oSMgntSpoolInfo)
		{
			row[CalculateCode] = oSMgntSpoolInfo.CalculateCode;
			row[Spool_oid] = oSMgntSpoolInfo.Spool_oid;
			row[SpoolFullName] = oSMgntSpoolInfo.Spool;
			row[Block_oid] = oSMgntSpoolInfo.Block_oid;
			row[Status] = oSMgntSpoolInfo.RowStatus;

			row[SpoolStatusDisplay] = oSMgntSpoolInfo.SpoolStatus;
			row[NameDisplay] = oSMgntSpoolInfo.Name;
			row[DrawNoDisplay] = oSMgntSpoolInfo.DrawNo;
			row[PageNoDisplay] = oSMgntSpoolInfo.PageNo;
			row[WeightDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.Weight), 2);
			row[TypeDisplay] = oSMgntSpoolInfo.Type;
			row[GroupTypeDisplay] = oSMgntSpoolInfo.GroupType;
			row[SpecNameDisplay] = oSMgntSpoolInfo.SpecName;
			row[TestPressureDisplay] = oSMgntSpoolInfo.TestPressure;
			row[InnerTreatmentDisplay] = oSMgntSpoolInfo.InnerTreatment;
			row[OutterTreatmentDisplay] = oSMgntSpoolInfo.OutterTreatment;
			row[ResponseDisplay] = oSMgntSpoolInfo.CreateBy;
			row[UpdateTimeDisplay] = oSMgntSpoolInfo.UpdateTime;
			row[StartInfoDisplay] = oSMgntSpoolInfo.StartInfo;
			row[EndInfoDisplay] = oSMgntSpoolInfo.EndInfo;

			row[SpoolFromModel] = oSMgntSpoolInfo.SpoolFromModel;
		}

		internal static void SetRowContent(DataGridViewRow row, SMgnt_SpoolInfo oSMgntSpoolInfo)
		{
			row.Cells[CalculateCode].Value = oSMgntSpoolInfo.CalculateCode;
			row.Cells[Spool_oid].Value = oSMgntSpoolInfo.Spool_oid;
			row.Cells[SpoolFullName].Value = oSMgntSpoolInfo.Spool;
			row.Cells[Block_oid].Value = oSMgntSpoolInfo.Block_oid;
			row.Cells[Status].Value = oSMgntSpoolInfo.RowStatus;

			row.Cells[SpoolStatusDisplay].Value = oSMgntSpoolInfo.SpoolStatus;
			row.Cells[NameDisplay].Value = oSMgntSpoolInfo.Name;
			row.Cells[DrawNoDisplay].Value = oSMgntSpoolInfo.DrawNo;
			row.Cells[PageNoDisplay].Value = oSMgntSpoolInfo.PageNo;
			row.Cells[WeightDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.Weight), 2);
			row.Cells[TypeDisplay].Value = oSMgntSpoolInfo.Type;
			row.Cells[GroupTypeDisplay].Value = oSMgntSpoolInfo.GroupType;
			row.Cells[SpecNameDisplay].Value = oSMgntSpoolInfo.SpecName;
			row.Cells[TestPressureDisplay].Value = oSMgntSpoolInfo.TestPressure;
			row.Cells[InnerTreatmentDisplay].Value = oSMgntSpoolInfo.InnerTreatment;
			row.Cells[OutterTreatmentDisplay].Value = oSMgntSpoolInfo.OutterTreatment;
			row.Cells[ResponseDisplay].Value = oSMgntSpoolInfo.CreateBy;
			row.Cells[UpdateTimeDisplay].Value = oSMgntSpoolInfo.UpdateTime;
			row.Cells[StartInfoDisplay].Value = oSMgntSpoolInfo.StartInfo;
			row.Cells[EndInfoDisplay].Value = oSMgntSpoolInfo.EndInfo;

			row.Cells[SpoolFromModel].Value = oSMgntSpoolInfo.SpoolFromModel;
		}

		internal static DataTable BuildDataTable(List<SMgnt_SpoolInfo> listSMgntSpools)
		{
			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntSpools)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//设置数据源
			oDateGridView.DataSource = oDT.DefaultView;

			//隐藏列
			oDateGridView.Columns[Spool_oid].Visible = false;
			oDateGridView.Columns[Block_oid].Visible = false;
			oDateGridView.Columns[SpoolFullName].Visible = false;
			oDateGridView.Columns[Status].Visible = false;
			oDateGridView.Columns[CalculateCode].Visible = false;
			oDateGridView.Columns[SpoolFromModel].Visible = false;

			//设置列宽
			oDateGridView.Columns[SpoolStatusDisplay].Width = 80;
			oDateGridView.Columns[NameDisplay].Width = 120;
			oDateGridView.Columns[DrawNoDisplay].Width = 140;
			oDateGridView.Columns[PageNoDisplay].Width = 40;
			oDateGridView.Columns[WeightDisplay].Width = 60;
			oDateGridView.Columns[TypeDisplay].Width = 60;
			oDateGridView.Columns[GroupTypeDisplay].Width = 60;
			oDateGridView.Columns[SpecNameDisplay].Width = 60;
			oDateGridView.Columns[TestPressureDisplay].Width = 60;
			oDateGridView.Columns[InnerTreatmentDisplay].Width = 80;
			oDateGridView.Columns[OutterTreatmentDisplay].Width = 80;
			oDateGridView.Columns[StartInfoDisplay].Width = 50;
			oDateGridView.Columns[EndInfoDisplay].Width = 50;
			oDateGridView.Columns[UpdateTimeDisplay].Width = 100;
			oDateGridView.Columns[ResponseDisplay].Width = 100;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[NameDisplay], ListSortDirection.Ascending);

			//激活第一项
			if (oDateGridView.RowCount != 0)
			{
				oDateGridView.BindingContext[oDateGridView.DataSource].Position = 0;
			}
		}

	}

	class SpoolPlusInfoTable
	{
		#region 
		public static string PlusSpoolDescription = "PlusSpoolDescription";
		public static string PlusSpoolDescriptionDisplay = "小票描述";
		public static string PlusSpoolMaterialGrade = "PlusSpoolMaterialGrade";
		public static string PlusSpoolMaterialGradeDisplay = "材料级别";
		public static string PlusSpoolClass = "PlusSpoolClass";
		public static string PlusSpoolClassDisplay = "等级";
		public static string PlusIsSRTP = "PlusIsSRTP";
		public static string PlusIsSRTPDisplay = "是否安全返港";
		public static string PlusProductionLine = "PlusProductionLine";
		public static string PlusProductionLineDisplay = "管线";
		public static string PlusInnerSurfaceArea = "PlusInnerSurfaceArea";
		public static string PlusInnerSurfaceAreaDisplay = "内表面积";
		public static string PlusOuterSurfaceArea = "PlusOuterSurfaceArea";
		public static string PlusOuterSurfaceAreaDisplay = "外表面积";
		public static string PlusSpoolLength = "PlusSpoolLength";
		public static string PlusSpoolLengthDisplay = "小票长度";
		public static string PlusSpoolNPD = "PlusSpoolNPD";
		public static string PlusSpoolNPDDisplay = "通径";
		public static string PlusSpoolPOD = "PlusSpoolPOD";
		public static string PlusSpoolPODDisplay = "外径";
		public static string PlusSpoolWallThickness = "PlusSpoolWallThickness";
		public static string PlusSpoolWallThicknessDisplay = "壁厚";
		public static string PlusWBS = "PlusWBS";
		public static string PlusWBSDisplay = "WBS";
		#endregion

		/// <summary>
		/// 构建一个包含指定列的table表
		/// </summary>
		/// <returns></returns>
		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("SpoolPlusInfo");
			dt.Columns.Add(PlusSpoolDescriptionDisplay, typeof(string));
			dt.Columns.Add(PlusSpoolMaterialGradeDisplay, typeof(string));
			dt.Columns.Add(PlusSpoolClassDisplay, typeof(string));
			dt.Columns.Add(PlusIsSRTPDisplay, typeof(int));
			dt.Columns.Add(PlusProductionLineDisplay, typeof(string));
			dt.Columns.Add(PlusInnerSurfaceAreaDisplay, typeof(double));
			dt.Columns.Add(PlusOuterSurfaceAreaDisplay, typeof(double));
			dt.Columns.Add(PlusSpoolLengthDisplay, typeof(double));
			dt.Columns.Add(PlusSpoolNPDDisplay, typeof(double));
			dt.Columns.Add(PlusSpoolPODDisplay, typeof(double));
			dt.Columns.Add(PlusSpoolWallThicknessDisplay, typeof(double));
			dt.Columns.Add(PlusWBSDisplay, typeof(string));

			return dt;
		}

		/// <summary>
		/// 将小票信息构建成tableRow
		/// </summary>
		/// <param name="oSMgntSpoolInfo"></param>
		/// <param name="dr"></param>
		internal static void AddRow(DataTable oDT, SMgnt_SpoolInfo oSMgntSpoolInfo)
		{
			DataRow dr = oDT.NewRow();

			SetRowContent(dr, oSMgntSpoolInfo);

			oDT.Rows.Add(dr);
		}

		internal static void SetRowContent(DataRow row, SMgnt_SpoolInfo oSMgntSpoolInfo)
		{
			row[PlusSpoolDescriptionDisplay] = oSMgntSpoolInfo.PlusSpoolDescription;
			row[PlusSpoolMaterialGradeDisplay] = oSMgntSpoolInfo.PlusSpoolMaterialGrade;
			row[PlusSpoolClassDisplay] = oSMgntSpoolInfo.PlusSpoolClass;
			row[PlusIsSRTPDisplay] = oSMgntSpoolInfo.PlusIsSRTP;
			row[PlusProductionLineDisplay] = oSMgntSpoolInfo.PlusProductionLine;
			row[PlusInnerSurfaceAreaDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusInnerSurfaceArea), 2); 
			row[PlusOuterSurfaceAreaDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusOuterSurfaceArea), 2);
			row[PlusSpoolLengthDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolLength), 2); 
			row[PlusSpoolNPDDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolNPD), 2); 
			row[PlusSpoolPODDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolPOD), 2);
			row[PlusSpoolWallThicknessDisplay] = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolWallThickness), 2);
			row[PlusWBSDisplay] = oSMgntSpoolInfo.PlusWBS;
		}

		internal static void SetRowContent(DataGridViewRow row, SMgnt_SpoolInfo oSMgntSpoolInfo)
		{
			row.Cells[PlusSpoolDescriptionDisplay].Value = oSMgntSpoolInfo.PlusSpoolDescription;
			row.Cells[PlusSpoolMaterialGradeDisplay].Value = oSMgntSpoolInfo.PlusSpoolMaterialGrade;
			row.Cells[PlusSpoolClassDisplay].Value = oSMgntSpoolInfo.PlusSpoolClass;
			row.Cells[PlusIsSRTPDisplay].Value = oSMgntSpoolInfo.PlusIsSRTP;
			row.Cells[PlusProductionLineDisplay].Value = oSMgntSpoolInfo.PlusProductionLine;
			row.Cells[PlusInnerSurfaceAreaDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusInnerSurfaceArea), 2);
			row.Cells[PlusOuterSurfaceAreaDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusOuterSurfaceArea), 2);
			row.Cells[PlusSpoolLengthDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolLength), 2);
			row.Cells[PlusSpoolNPDDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolNPD), 2);
			row.Cells[PlusSpoolPODDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolPOD), 2);
			row.Cells[PlusSpoolWallThicknessDisplay].Value = Math.Round(Convert.ToDouble(oSMgntSpoolInfo.PlusSpoolWallThickness), 2);
			row.Cells[PlusWBSDisplay].Value = oSMgntSpoolInfo.PlusWBS;

		}

		internal static DataTable BuildDataTable(SMgnt_SpoolInfo oSMgntSpools)
		{
			DataTable oDataTable = NewTable();

			//构建行数据
			AddRow(oDataTable, oSMgntSpools);

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//设置数据源
			oDateGridView.DataSource = oDT;

			//设置列宽
			oDateGridView.Columns[PlusSpoolDescriptionDisplay].Width = 460;
			oDateGridView.Columns[PlusSpoolMaterialGradeDisplay].Width = 60;
			oDateGridView.Columns[PlusSpoolClassDisplay].Width = 60;
			oDateGridView.Columns[PlusIsSRTPDisplay].Width = 60;
			oDateGridView.Columns[PlusProductionLineDisplay].Width = 60;
			oDateGridView.Columns[PlusInnerSurfaceAreaDisplay].Width = 60;
			oDateGridView.Columns[PlusOuterSurfaceAreaDisplay].Width = 60;
			oDateGridView.Columns[PlusSpoolLengthDisplay].Width = 60;
			oDateGridView.Columns[PlusSpoolNPDDisplay].Width = 60;
			oDateGridView.Columns[PlusSpoolPODDisplay].Width = 60;
			oDateGridView.Columns[PlusSpoolWallThicknessDisplay].Width = 60;
			oDateGridView.Columns[PlusWBSDisplay].Width = 60;

			//激活第一项
			if (oDateGridView.RowCount != 0)
			{
				oDateGridView.BindingContext[oDateGridView.DataSource].Position = 0;
			}
		}

	}

	class PipePartTable
	{
		#region 
		public static string Spool = "Spool";//Hide
		public static string Part_oid = "PartOid";//Hide
		public static string QtyDesc = "QtyDesc";//Hide
		public static string Priority = "Priority";//Hide
		public static string Class = "Class";//Hide

		public static string Tag = "Tag";
		public static string TagDisplay = "编码";
		public static string MatCode = "MatCode";
		public static string MatCodeDisplay = "物资编码";
		public static string MatDesc = "MatDesc";
		public static string MatDescDisplay = "物资描述";
		public static string GeometryStd = "GeometryStd";
		public static string GeometryStdDisplay = "制造标准";
		public static string EndCut = "EndCut";
		public static string EndCutDisplay = "端部处理方式";
		public static string Qty = "Qty";
		public static string QtyDisplay = "数量/下料长度";
		public static string BendPlus = "BendPlus";
		public static string BendPlusDisplay = "弯管加长长度";
		public static string ModelLen = "ModelLen";
		public static string ModelLenDisplay = "模型长度";
		public static string Weight = "Weight";
		public static string WeightDisplay = "单重";
		public static string PriorityDisplay = "主支管";

		#endregion

		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("PipePart");
			dt.Columns.Add(Spool, typeof(string));
			dt.Columns.Add(Part_oid, typeof(string));

			dt.Columns.Add(TagDisplay, typeof(string));
			dt.Columns.Add(PriorityDisplay, typeof(string));
			dt.Columns.Add(MatCodeDisplay, typeof(string));
			dt.Columns.Add(MatDescDisplay, typeof(string));
			dt.Columns.Add(GeometryStdDisplay, typeof(string));
			dt.Columns.Add(EndCutDisplay, typeof(string));
			dt.Columns.Add(QtyDisplay, typeof(double));
			dt.Columns.Add(BendPlusDisplay, typeof(double));
			dt.Columns.Add(ModelLenDisplay, typeof(double));
			dt.Columns.Add(WeightDisplay, typeof(double));

			return dt;
		}

		internal static void AddRow(DataTable oDT, SMgnt_PipePart oSMgntPipePart)
		{
			DataRow dr = oDT.NewRow();

			dr[Part_oid] = oSMgntPipePart.Part_oid;
			dr[Spool] = oSMgntPipePart.Spool;

			//将tag修改为两位，以便显示排序正常
			if(oSMgntPipePart.Tag.Length == 1)
				dr[TagDisplay] = "0" + oSMgntPipePart.Tag;
			else
				dr[TagDisplay] = oSMgntPipePart.Tag;
			dr[PriorityDisplay] = oSMgntPipePart.Priority;
			dr[MatCodeDisplay] = oSMgntPipePart.MatCode;
			dr[MatDescDisplay] = oSMgntPipePart.MatDesc;
			dr[GeometryStdDisplay] = oSMgntPipePart.GeometryStd;
			dr[EndCutDisplay] = oSMgntPipePart.EndCut;
			dr[QtyDisplay] = Math.Round(Convert.ToDouble(oSMgntPipePart.Qty), 2);
			dr[BendPlusDisplay] = Math.Round(Convert.ToDouble(oSMgntPipePart.BendPlus), 2);
			dr[ModelLenDisplay] = Math.Round(Convert.ToDouble(oSMgntPipePart.ModelLen), 2);
			dr[WeightDisplay] = Math.Round(Convert.ToDouble(oSMgntPipePart.Weight), 2);

			oDT.Rows.Add(dr);
		}

		internal static DataTable BuildDataTable(List<SMgnt_PipePart> listSMgntPipeParts)
		{
		
			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntPipeParts)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//绑定数据
			oDateGridView.DataSource = oDT;

			//隐藏列
			oDateGridView.Columns[PipePartTable.Part_oid].Visible = false;
			oDateGridView.Columns[PipePartTable.Spool].Visible = false;

			//设置列宽
			oDateGridView.Columns[PipePartTable.TagDisplay].Width = 60;
			oDateGridView.Columns[PipePartTable.PriorityDisplay].Width = 60;
			oDateGridView.Columns[PipePartTable.MatCodeDisplay].Width = 120;
			oDateGridView.Columns[PipePartTable.MatDescDisplay].Width = 440;
			oDateGridView.Columns[PipePartTable.GeometryStdDisplay].Width = 60;
			oDateGridView.Columns[PipePartTable.EndCutDisplay].Width = 80;
			oDateGridView.Columns[PipePartTable.QtyDisplay].Width = 80;
			oDateGridView.Columns[PipePartTable.BendPlusDisplay].Width = 80;
			oDateGridView.Columns[PipePartTable.ModelLenDisplay].Width = 80;
			oDateGridView.Columns[PipePartTable.WeightDisplay].Width = 60;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[PipePartTable.TagDisplay], ListSortDirection.Ascending);
		}

	}

	class PipeWeldTable
	{
		#region 
		public static string Spool = "SpoolName";//Hide
		public static string Weld_oid = "WeldOid";//Hide

		public static string Tag = "Tag";
		public static string TagDisplay = "编码";
		public static string Type = "Type";
		public static string TypeDisplay = "类型";
		public static string Code = "Code";
		public static string CodeDisplay = "类型编码";
		public static string Size = "Size";
		public static string SizeDisplay = "尺寸";
		public static string Thickness = "Thickness";
		public static string ThicknessDisplay = "高度";
		public static string Conn = "Conn";
		public static string ConnDisplay = "首尾连接部件";
		public static string ConnDesc = "ConnDesc";
		public static string ConnDescDisplay = "首尾连接部件描述";
		public static string PipeGrade = "PipeGrade";
		public static string PipeGradeDisplay = "等级";
		public static string Stage = "Stage";
		public static string StageDisplay = "阶段";
		#endregion

		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("PipeWeld");
			dt.Columns.Add(Spool, typeof(string));
			dt.Columns.Add(Weld_oid, typeof(string));

			dt.Columns.Add(TagDisplay, typeof(string));
			dt.Columns.Add(SizeDisplay, typeof(string));
			dt.Columns.Add(ThicknessDisplay, typeof(string));
			dt.Columns.Add(ConnDisplay, typeof(string));
			dt.Columns.Add(ConnDescDisplay, typeof(string));
			dt.Columns.Add(TypeDisplay, typeof(string));
			dt.Columns.Add(CodeDisplay, typeof(string));
			dt.Columns.Add(PipeGradeDisplay, typeof(string));
			dt.Columns.Add(StageDisplay, typeof(string));

			return dt;
		}

		internal static void AddRow(DataTable oDT, SMgnt_PipeWeld oSMgntPipeWeld)
		{
			DataRow dr = oDT.NewRow();

			dr[Weld_oid] = oSMgntPipeWeld.Weld_oid;
			dr[Spool] = oSMgntPipeWeld.Spool;

			dr[TagDisplay] = oSMgntPipeWeld.Tag;
			dr[TypeDisplay] = oSMgntPipeWeld.Type;
			dr[CodeDisplay] = oSMgntPipeWeld.Code;
			dr[SizeDisplay] = oSMgntPipeWeld.Size;
			dr[ThicknessDisplay] = oSMgntPipeWeld.Thickness;
			dr[ConnDisplay] = oSMgntPipeWeld.Conn;
			dr[ConnDescDisplay] = oSMgntPipeWeld.ConnDesc;
			dr[PipeGradeDisplay] = oSMgntPipeWeld.PipeGrade;
			dr[StageDisplay] = oSMgntPipeWeld.Stage;

			oDT.Rows.Add(dr);
		}

		internal static DataTable BuildDataTable(List<SMgnt_PipeWeld> listSMgntPipeWelds)
		{

			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntPipeWelds)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//绑定数据
			oDateGridView.DataSource = oDT;

			//隐藏列
			oDateGridView.Columns[PipeWeldTable.Weld_oid].Visible = false;
			oDateGridView.Columns[PipeWeldTable.Spool].Visible = false;

			//设置列宽
			oDateGridView.Columns[PipeWeldTable.TagDisplay].Width = 80;
			oDateGridView.Columns[PipeWeldTable.SizeDisplay].Width = 80;
			oDateGridView.Columns[PipeWeldTable.ThicknessDisplay].Width = 80;
			oDateGridView.Columns[PipeWeldTable.ConnDisplay].Width = 120;
			oDateGridView.Columns[PipeWeldTable.ConnDescDisplay].Width = 240;
			oDateGridView.Columns[PipeWeldTable.TypeDisplay].Width = 80;
			oDateGridView.Columns[PipeWeldTable.CodeDisplay].Width = 80;
			oDateGridView.Columns[PipeWeldTable.PipeGradeDisplay].Width = 80;
			oDateGridView.Columns[PipeWeldTable.StageDisplay].Width = 80;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[PipeWeldTable.TagDisplay], ListSortDirection.Ascending);
		}

	}

	class PipeBendTable
	{
		#region 
		public static string Spool = "Spool";//Hide
		public static string TurnFeature_oid = "OID";//Hide
		public static string Part_oid = "PartOid";//Hide

		public static string Tag = "TAG";
		public static string TagDisplay = "编码";
		public static string PullLen = "PULL";
		public static string PullLenDisplay = "送进量";
		public static string BendRadius = "BR";
		public static string BendRadiusDisplay = "弯模半径";
		public static string BendAgnle = "BEND";
		public static string BendAgnleDisplay = "弯角";
		public static string TurnAngle = "TURN";
		public static string TurnAngleDisplay = "转角";
		public static string CutLen = "CUTPLUS";
		public static string CutLenDisplay = "前切长";
		public static string BendStartLen = "LENGTH";
		public static string BendStartLenDisplay = "起弯点";
		public static string TailCutLen = "TAILCUT";
		public static string TailCutLenDisplay = "尾切长";
		#endregion

		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("PipeBend");
			dt.Columns.Add(Spool, typeof(string));
			dt.Columns.Add(TurnFeature_oid, typeof(string));
			dt.Columns.Add(Part_oid, typeof(string));

			dt.Columns.Add(TagDisplay, typeof(string));
			dt.Columns.Add(PullLenDisplay, typeof(string));
			dt.Columns.Add(BendRadiusDisplay, typeof(string));
			dt.Columns.Add(BendAgnleDisplay, typeof(string));
			dt.Columns.Add(TurnAngleDisplay, typeof(string));
			dt.Columns.Add(CutLenDisplay, typeof(string));
			dt.Columns.Add(BendStartLenDisplay, typeof(string));
			dt.Columns.Add(TailCutLenDisplay, typeof(string));

			return dt;
		}

		internal static void AddRow(DataTable oDT, SMgnt_PipeBend oSMgntPipeBend)
		{
			DataRow dr = oDT.NewRow();

			dr[TurnFeature_oid] = oSMgntPipeBend.TurnFeature_oid;
			dr[Spool] = oSMgntPipeBend.Spool;
			dr[Part_oid] = oSMgntPipeBend.Part_oid;

			dr[TagDisplay] = oSMgntPipeBend.Tag;
			dr[PullLenDisplay] = oSMgntPipeBend.PullLen;
			dr[BendRadiusDisplay] = oSMgntPipeBend.BendRadius;
			dr[BendAgnleDisplay] = oSMgntPipeBend.BendAngle;
			dr[TurnAngleDisplay] = oSMgntPipeBend.TurnAngle;
			dr[CutLenDisplay] = oSMgntPipeBend.CutLen;
			dr[BendStartLenDisplay] = oSMgntPipeBend.BendStartLen;
			dr[TailCutLenDisplay] = oSMgntPipeBend.TailCutLen;

			oDT.Rows.Add(dr);
		}

		internal static DataTable BuildDataTable(List<SMgnt_PipeBend> listSMgntPipeBends)
		{

			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntPipeBends)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//绑定数据
			oDateGridView.DataSource = oDT;

			//隐藏列
			oDateGridView.Columns[PipeBendTable.TurnFeature_oid].Visible = false;
			oDateGridView.Columns[PipeBendTable.Spool].Visible = false;
			oDateGridView.Columns[PipeBendTable.Part_oid].Visible = false;

			//设置列宽
			oDateGridView.Columns[PipeBendTable.TagDisplay].Width = 80;
			oDateGridView.Columns[PipeBendTable.PullLenDisplay].Width = 120;
			oDateGridView.Columns[PipeBendTable.BendRadiusDisplay].Width = 120;
			oDateGridView.Columns[PipeBendTable.BendAgnleDisplay].Width = 120;
			oDateGridView.Columns[PipeBendTable.TurnAngleDisplay].Width = 120;
			oDateGridView.Columns[PipeBendTable.CutLenDisplay].Width = 120;
			oDateGridView.Columns[PipeBendTable.BendStartLenDisplay].Width = 120;
			oDateGridView.Columns[PipeBendTable.TailCutLenDisplay].Width = 120;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[PipeBendTable.TagDisplay], ListSortDirection.Ascending);
		}

	}

	class PipeCheckTable
	{
		#region 
		public static string Spool = "Spool";//Hide
		public static string Part_oid = "PartOid";//Hide

		public static string Tag = "Tag";
		public static string TagDisplay = "管路编号";
		public static string OrderedLens = "OrderedLens";
		public static string OrderedLensDisplay = "顺序长度";
		public static string SaddleCut = "SaddleCut";
		public static string SaddleCutDisplay = "马鞍切值";
		public static string MiterCut = "MiterCut";
		public static string MiterCutDisplay = "对焊切值";
		#endregion

		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("PipeCheck");
			dt.Columns.Add(Spool, typeof(string));
			dt.Columns.Add(Part_oid, typeof(string));

			dt.Columns.Add(TagDisplay, typeof(string));
			dt.Columns.Add(OrderedLensDisplay, typeof(string));
			dt.Columns.Add(SaddleCutDisplay, typeof(string));
			dt.Columns.Add(MiterCutDisplay, typeof(string));

			return dt;
		}

		internal static void AddRow(DataTable oDT, SMgnt_PipeCheck oSMgntPipeCheck)
		{
			DataRow dr = oDT.NewRow();

			dr[Part_oid] = oSMgntPipeCheck.Part_oid;
			dr[Spool] = oSMgntPipeCheck.Spool;

			dr[TagDisplay] = oSMgntPipeCheck.Tag;
			dr[OrderedLensDisplay] = oSMgntPipeCheck.OrderedLens;
			dr[SaddleCutDisplay] = oSMgntPipeCheck.SaddleCut;
			dr[MiterCutDisplay] = oSMgntPipeCheck.MiterCut;

			oDT.Rows.Add(dr);
		}

		internal static DataTable BuildDataTable(List<SMgnt_PipeCheck> listSMgntPipeChecks)
		{

			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntPipeChecks)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//绑定数据
			oDateGridView.DataSource = oDT;

			//隐藏列
			oDateGridView.Columns[PipeCheckTable.Spool].Visible = false;
			oDateGridView.Columns[PipeCheckTable.Part_oid].Visible = false;

			//设置列宽
			oDateGridView.Columns[PipeCheckTable.TagDisplay].Width = 80;
			oDateGridView.Columns[PipeCheckTable.OrderedLensDisplay].Width = 300;
			oDateGridView.Columns[PipeCheckTable.SaddleCutDisplay].Width = 300;
			oDateGridView.Columns[PipeCheckTable.MiterCutDisplay].Width = 300;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[PipeCheckTable.TagDisplay], ListSortDirection.Ascending);
		}

	}

	class PipeAssemblyTable
	{
		#region 
		public static string Spool = "Spool";//Hide
		public static string Part_oid = "PartOid";//Hide
		public static string RefPartOid = "RefOid";//Hide

		public static string Tag = "Tag";
		public static string TagDisplay = "编码";
		public static string FlangeTurnAngle = "FR";
		public static string FlangeTurnAngleDisplay = "法兰转角";
		public static string BranchTurnAngle = "BR";
		public static string BranchTurnAngleDisplay = "支管转角";
		public static string BranchAngle = "BA";
		public static string BranchAngleDisplay = "支管夹角";
		public static string RefPartTag = "RefTag";
		public static string RefPartTagDisplay = "参考对象";
		#endregion

		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("PipeAssembly");
			dt.Columns.Add(Spool, typeof(string));
			dt.Columns.Add(Part_oid, typeof(string));

			dt.Columns.Add(TagDisplay, typeof(string));
			dt.Columns.Add(FlangeTurnAngleDisplay, typeof(string));
			dt.Columns.Add(BranchAngleDisplay, typeof(string));
			dt.Columns.Add(BranchTurnAngleDisplay, typeof(string));
			dt.Columns.Add(RefPartTagDisplay, typeof(string));

			return dt;
		}

		internal static void AddRow(DataTable oDT, SMgnt_PipeAssembly oSMgntPipeAssembly)
		{
			DataRow dr = oDT.NewRow();

			dr[Part_oid] = oSMgntPipeAssembly.Part_oid;
			dr[Spool] = oSMgntPipeAssembly.Spool;

			//将tag修改为两位，以便显示排序正常
			if (oSMgntPipeAssembly.Tag.Length == 1)
				dr[TagDisplay] = "0" + oSMgntPipeAssembly.Tag;
			else
				dr[TagDisplay] = oSMgntPipeAssembly.Tag;
			dr[FlangeTurnAngleDisplay] = oSMgntPipeAssembly.FlangeTurnAngle;
			dr[BranchTurnAngleDisplay] = oSMgntPipeAssembly.BranchTurnAngle;
			dr[BranchAngleDisplay] = oSMgntPipeAssembly.BranchAngle;
			dr[RefPartTagDisplay] = oSMgntPipeAssembly.RefPartTag;

			oDT.Rows.Add(dr);
		}

		internal static DataTable BuildDataTable(List<SMgnt_PipeAssembly> listSMgntPipeAssemblies)
		{

			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntPipeAssemblies)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//绑定数据
			oDateGridView.DataSource = oDT;

			//隐藏列
			oDateGridView.Columns[PipeAssemblyTable.Spool].Visible = false;
			oDateGridView.Columns[PipeAssemblyTable.Part_oid].Visible = false;

			//设置列宽
			oDateGridView.Columns[PipeAssemblyTable.TagDisplay].Width = 100;
			oDateGridView.Columns[PipeAssemblyTable.FlangeTurnAngleDisplay].Width = 100;
			oDateGridView.Columns[PipeAssemblyTable.BranchTurnAngleDisplay].Width = 100;
			oDateGridView.Columns[PipeAssemblyTable.BranchAngleDisplay].Width = 100;
			oDateGridView.Columns[PipeAssemblyTable.RefPartTagDisplay].Width = 100;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[PipeAssemblyTable.TagDisplay], ListSortDirection.Ascending);
		}

	}

	class PipeIssueTable
	{
		#region 
		public static string Spool = "Spool";//Hide
		public static string Id = "index";//Hide
		public static string RelatedTable = "RelatedTable";//Hide
		

		public static string Part = "Part";
		public static string PartDisplay = "问题部件";
		public static string Issue = "Issue";
		public static string IssueDisplay = "问题描述";
		public static string Lever = "Level";
		public static string LeverDisplay = "问题级别";

		#endregion

		internal static DataTable NewTable()
		{
			DataTable dt = new DataTable("PipeWeld");
			dt.Columns.Add(Spool, typeof(string));
			dt.Columns.Add(Id, typeof(string));
			dt.Columns.Add(RelatedTable, typeof(string));

			dt.Columns.Add(PartDisplay, typeof(string));
			dt.Columns.Add(IssueDisplay, typeof(string));
			dt.Columns.Add(LeverDisplay, typeof(string));

			return dt;
		}

		internal static void AddRow(DataTable oDT, SMgnt_PipeIssue oSMgntPipeIssue)
		{
			DataRow dr = oDT.NewRow();

			dr[Id] = oSMgntPipeIssue.Id;
			dr[Spool] = oSMgntPipeIssue.Spool;
			dr[RelatedTable] = oSMgntPipeIssue.RelatedTable;

			dr[PartDisplay] = oSMgntPipeIssue.Part;
			dr[IssueDisplay] = oSMgntPipeIssue.Issue;
			dr[LeverDisplay] = oSMgntPipeIssue.Level;

			oDT.Rows.Add(dr);
		}

		internal static DataTable BuildDataTable(List<SMgnt_PipeIssue> listSMgntPipeIssues)
		{

			DataTable oDataTable = NewTable();

			//构建行数据
			foreach (var it in listSMgntPipeIssues)
			{
				AddRow(oDataTable, it);
			}

			return oDataTable;
		}

		internal static void SetDTAndFormat(DataGridView oDateGridView, DataTable oDT)
		{
			//绑定数据
			oDateGridView.DataSource = oDT;

			//隐藏列
			oDateGridView.Columns[PipeIssueTable.Spool].Visible = false;
			oDateGridView.Columns[PipeIssueTable.Id].Visible = false;
			oDateGridView.Columns[PipeIssueTable.RelatedTable].Visible = false;

			//设置列宽
			oDateGridView.Columns[PipeIssueTable.PartDisplay].Width = 200;
			oDateGridView.Columns[PipeIssueTable.IssueDisplay].Width = 840;
			oDateGridView.Columns[PipeIssueTable.LeverDisplay].Width = 80;

			//排序
			oDateGridView.Sort(oDateGridView.Columns[PipeIssueTable.LeverDisplay], ListSortDirection.Ascending);
		}

	}

}
